<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>

<f:metadata>
	<f:viewParam name="tpid" value="#{packageBean.TPId}" />
	<f:viewParam name="lid" value="#{packageBean.locationId}" />
	<f:viewAction action="#{packageBean.init}" />
</f:metadata>

<h:body>
	<h:form id="form">
		<p:panelGrid id="packGrid">
			<p:row>
				<p:column>
					<h:outputLabel value="Package name " for="nameChoice" />
				</p:column>
				<p:column>
					<p:inputText id="nameChoice" value="#{packageBean.myTP.name}"
						size="25" />
				</p:column>
				<p:column>
					<p:message for="nameChoice" />
				</p:column>
			</p:row>

			<p:row>
				<p:column>
					<h:outputLabel value="Transport mean " for="meanTable" />
				</p:column>
				<p:column>
					<p:dataTable id="meanTable" var="m"
						value="#{packageBean.meanDataModel}"
						selection="#{packageBean.myTP.mean}" selectionMode="single"
						rowKey="#{m.productId}">
						<p:column headerText="Name">
	    			#{m.name}
	    		</p:column>
						<p:column headerText="Departure">
	    			#{m.departure.name}
	    		</p:column>
						<p:column headerText="Price">
	    			#{m.price.toPlainString()}
	    		</p:column>
						<p:column headerText="Spaces">
	    			#{m.spaces}
	    		</p:column>
					</p:dataTable>
				</p:column>
				<p:column>
					<p:message for="meanTable" />
				</p:column>
			</p:row>
			<p:row>
				<p:column>
					<h:outputLabel value="Hotel " for="hotelTable" />
				</p:column>
				<p:column>
					<p:dataTable id="hotelTable" var="h"
						value="#{packageBean.hotelDataModel}"
						selection="#{packageBean.myTP.hotel}" selectionMode="single"
						rowKey="#{h.productId}">
						<p:column headerText="Name">
	    			#{h.name}
	    		</p:column>

						<p:column headerText="Rooms">
							<p:dataList value="#{packageBean.getRoomsAsList(h)}" var="r"
								itemType="circle">  
	    	 #{r.type.toString()}: #{r.totalRooms}, at #{r.price.toPlainString()} € 
					</p:dataList>
						</p:column>
					</p:dataTable>
				</p:column>
				<p:column>
					<p:message for="hotelTable" />
				</p:column>
			</p:row>
			<p:row>
				<p:column>
					<h:outputLabel value="Excursion " for="exTable" />
				</p:column>
				<p:column>
					<p:dataTable id="exTable" var="ex"
						value="#{packageBean.exsDataModel}"
						selection="#{packageBean.selectedExs}">

						<p:column selectionMode="multiple" style="width:1%" />

						<p:column headerText="Excursion name" style="width:33%">  
            #{ex.name}  
        </p:column>

						<p:column headerText="Price" style="width:33%">
  			#{ex.price.toPlainString()}
  		</p:column>
						<p:column headerText="Excursion day" style="width:33%">  
            #{ex.weekDay.toString()}  
        </p:column>
					</p:dataTable>
				</p:column>
				<p:column>
					<p:message for="exTable" />
				</p:column>
			</p:row>
			<f:facet name="footer">
				<p:row>
					<p:column colspan="3">
						<p:commandButton rendered="#{packageBean.locationId != null}" 
						action="#{packageBean.addPackage()}" update=":form" value="Create travel package" />
						<p:commandButton rendered="#{packageBean.TPId != null}" 
						update=":form" action="#{packageBean.modifyPackage()}" value="Update travel package" />
					</p:column>
				</p:row>
			</f:facet>
		</p:panelGrid>
	</h:form>
</h:body>
</html>